<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件</title>
</head>

<body><img id="img" src="img/01.png" /><br>
    <button id="up" onclick="last()">上一张</button>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button id="down" onclick="next()">下一张</button>
</body>

<!-- 引入js -->
<script>
    let n = 2;
    // 点击后切换上一张
    function last() {
        //两张图片轮流切换
        if (n === 3) {
            n = 1;
        }
        //改变图片
        document.getElementById("img").src = "img/0" + n + ".png";
        n++;
    }

    // 点击后切换下一张
    function next() {
        //两张图片轮流切换
        if (n === 3) {
            n = 1;
        }
        //改变图片
        document.getElementById("img").src = "img/0" + n + ".png";
        n++;
    }
</script>

</html>